// node文件模块
const fs = require("fs");

// 图片转base64
function imgToBase64(url) {
  return new Promise((resolve, reject) => {
    fs.readFile(url, (err, data) => {
      if (err) {
        reject(err);
      } else {
        const buffer = Buffer.from(data, "binary");
        const base64 = buffer.toString("base64");
        resolve(base64);
      }
    });
  });
}

module.exports = {
  imgToBase64,
};
